//
//  MainTopView.m
//  SUZHOUBANK
//
//  Created by saberLily on 16/4/11.
//  Copyright © 2016年 RuiFeng-WGCC. All rights reserved.
//

#import "MainTopView.h"
#import "BtnmenuModel.h"
#import "CXXsingleton.h"
#import "LoginViewController.h"
#import "SelectphotoViewController.h"
#import "XActionSheet.h"
#import "XAlertView.h"
#import "CAlertShow.h"
#import "CAlertSettingView.h"
@interface MainTopView()<UIActionSheetDelegate,XAlertDelegate>
@property(nonatomic,strong)UIButton *infobtn;
@property(nonatomic,strong)UIButton *settingbtn;
@property(nonatomic,strong)UIButton *returnbtn;
@property(nonatomic,strong)UIButton *modifypassBtn;
@property(nonatomic,strong)UIButton *modifyheaderBtn;
@property(nonatomic,strong)UIImageView *headerImage;
@property(nonatomic,strong)UILabel *nameLable;
@property(nonatomic,strong)NSArray *titles;
@end
@implementation MainTopView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.infobtn];
        [self addSubview:self.settingbtn];
        [self addSubview:self.returnbtn];
        [self addSubview:self.headerImage];
        [self addSubview:self.modifyheaderBtn];
        [self addSubview:self.modifypassBtn];
        [self addSubview:self.nameLable];
    }
    return self;
}
- (void)respondsTomenubtn:(UIButton *)sender{
    NSMutableArray *obj = [NSMutableArray array];
    for (NSInteger i = 0; i < [self titles].count; i++) {
        BtnmenuModel * info = [BtnmenuModel new];
        info.title = [self titles][i];
        [obj addObject:info];
    }
    
    [[CXXsingleton shareManager]showPopMenuSelecteWithFrame:250
                                                       item:obj
                                                     action:^(NSInteger index) {
                                                         if (index == 1) {
                                                             LoginViewController *logVC = [[LoginViewController alloc]init];
                                                             [[UIApplication sharedApplication].keyWindow.rootViewController  presentViewController:logVC animated:YES completion:nil];
                                                         }
                                                         
                                                     }];
}
- (void)respondsToInfobtn:(UIButton *)sender{
    XAlertView *alert = [[XAlertView alloc]initWithTitleAndDesc:@"这是一个警告框" Desc:@"这里可以填一些详细内容"];
    alert.btnTitleArray = @[@"按钮一",@"按钮二",@"按钮三"];
    alert.delegate = self;
    [alert showAnimation1];
    
    
}
- (void)respondsToModifypassBtn:(UIButton *)sender{
    
    
}
- (void)respondsToRrturnbtn:(UIButton *)sender{
    
    [CAlertShow showAlertWithMessage:@" 您确定要退出了么"];
    
}
- (UIButton *)infobtn{
    if (_infobtn == nil) {
        _infobtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_infobtn setTitle:@"信息" forState:UIControlStateNormal];
        _infobtn.frame = CGRectMake(self.frame.size.width - 240, 20, 65, 70);
        [_infobtn setImage:[UIImage imageNamed:@"消息推送_菜单_信箱.png"] forState:UIControlStateNormal];
        [_infobtn addTarget:self action:@selector(respondsToInfobtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _infobtn;
}
- (UIButton *)settingbtn{
    if (_settingbtn == nil) {
        _settingbtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_settingbtn setTitle:@"设置.png" forState:UIControlStateNormal];
        _settingbtn.frame = CGRectMake(self.frame.size.width - 170, 20, 65, 70);
        [_settingbtn setImage:[UIImage imageNamed:@"设置.png"] forState:UIControlStateNormal];//给button添加image
        [_settingbtn addTarget:self action:@selector(respondsTosettingBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _settingbtn;
}
- (UIButton *)returnbtn{
    if (_returnbtn == nil) {
        _returnbtn =[UIButton buttonWithType:UIButtonTypeCustom];
        [_returnbtn setTitle:@"" forState:UIControlStateNormal];
        [_returnbtn setImage:[UIImage imageNamed:@"登出.png"] forState:UIControlStateNormal];
        _returnbtn.frame =CGRectMake(self.frame.size.width - 100, 20, 65, 70);
        [_returnbtn addTarget:self action:@selector(respondsToRrturnbtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _returnbtn;
}
- (void)respondsTosettingBtn:(UIButton *)sender{
    CAlertSettingView *settingView =[[CAlertSettingView alloc]init];
    [UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.7 initialSpringVelocity:2 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        settingView.center = self.center;
        [self addSubview:settingView];
    } completion:^(BOOL finished) {
        
    }];
    
}
- (UIImageView *)headerImage{
    if (_headerImage == nil) {
        _headerImage =[[UIImageView alloc]initWithFrame:CGRectMake(20, 20, 80, 80)];
        _headerImage.layer.cornerRadius = 40;
    }
    return _headerImage ;
}
- (UIButton *)modifyheaderBtn{
    if (_modifyheaderBtn == nil) {
        _modifyheaderBtn = [[UIButton alloc]initWithFrame:CGRectMake(self.headerImage.frame.origin.x + 90, 50,115 , 35)];
        [_modifyheaderBtn setImage:[UIImage imageNamed:@"个人信息_拍照_修改头像"] forState:UIControlStateNormal];
        [_modifyheaderBtn addTarget:self action:@selector(respondsTomenubtn:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _modifyheaderBtn ;
}
- (UIButton *)modifypassBtn{
    if (_modifypassBtn == nil) {
        _modifypassBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _modifypassBtn.frame = CGRectMake(self.modifyheaderBtn.frame.origin.x + 125, 50, 115, 35);
        [_modifypassBtn setImage:[UIImage imageNamed:@"修改密码.png"] forState:UIControlStateNormal];
        [_modifyheaderBtn addTarget:self action:@selector(respondsToModifypassBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _modifypassBtn;
}

- (UILabel *)nameLable{
    if (_nameLable == nil) {
        _nameLable = [[UILabel alloc]initWithFrame:CGRectMake(self.headerImage.frame.origin.x + 100, 20,200 , 30)];
        _nameLable.text = @"张静女士，您好！";
        _nameLable.font = [UIFont boldSystemFontOfSize:24.0f];
    }
    return _nameLable ;
}
- (NSArray *)titles{
    return @[@"上传头像",@"系统相册",@"相机"];
}

@end
